package user;

import operation.IOperation;
import operation.impl.*;

import java.util.Scanner;

/**
 * 普通用户类
 */
public class NormalUser extends User{
    private Scanner scanner=new Scanner(System.in);
    public NormalUser(String name){
        this.name=name;
        this.operations=new IOperation[]{
                //展示所有图书
                new DisplayOperation(),
                //查找书籍
                new FindOperation(),
                //借书
                new BorrowOperation(),
                //还书
                new ReturnOperation()
        };
    }

    @Override
    public int menu() {
        System.out.println("==================================");
        System.out.println("   欢迎"+this.name+"登录图书管理系统！");
        System.out.println("          1. 展示所有图书");
        System.out.println("          2. 查找书籍");
        System.out.println("          3. 借书");
        System.out.println("          4. 还书");
        System.out.println("          0. 退出");
        System.out.println("==================================");
        System.out.println("请输入您的选项：");
        int choice=scanner.nextInt();
        if(choice<0||choice>operations.length){
            System.out.println("你的输入有误！");
            return -1;
        }
        if(choice==0){
            scanner.close();
        }
        return choice;
    }
}
